//
//  MainTopCell.m
//  GoTraveling
//
//  Created by 陈金山 on 15/12/24.
//  Copyright © 2015年 开发华佗. All rights reserved.
//

#import "MainTopCell.h"
#import "TopCollectionViewCell.h"
#import "TypeTen.h"

@interface MainTopCell ()<UICollectionViewDataSource, UICollectionViewDelegate>

@property (nonatomic, retain) UILabel *titleName;

@property (nonatomic, retain) UICollectionView *collection;

@end

@implementation MainTopCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createSubViews];
        self.contentView.backgroundColor = [UIColor colorWithRed:0.980 green:0.961 blue:0.910 alpha:1.000];
    }
    
    return self;
}

- (void)createSubViews {
    
#pragma mark collectionView
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    
    flowLayout.itemSize = CGSizeMake((SCREEN_WIDTH - 32 * ADAPT_WIDTH) / 2, ADAPT_HEIGHT * 250);
    flowLayout.sectionInset = UIEdgeInsetsMake(0, 10 * ADAPT_WIDTH, 0, 10 * ADAPT_WIDTH);
    
    self.collection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 520 * ADAPT_HEIGHT) collectionViewLayout:flowLayout];
    self.collection.backgroundColor = self.backgroundColor;
    self.collection.delegate = self;
    self.collection.dataSource = self;
    [self.collection registerClass:[TopCollectionViewCell class] forCellWithReuseIdentifier:@"identify"];
    [self.contentView addSubview:self.collection];
}

- (void)setTenArray:(NSMutableArray *)tenArray
{
    _tenArray = tenArray;
    [self.collection reloadData];
}

#pragma mark cell点击事件
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    TypeTen *typeTen = [self.tenArray objectAtIndex:indexPath.row];
    [self.delegate pushViewController:[typeTen spot_id]];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return self.tenArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    TopCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"identify" forIndexPath:indexPath];
    
    cell.typeTen = [self.tenArray objectAtIndex:indexPath.row];
    
    return cell;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
